x`<template>
  <h1>挂号信息</h1>
  <el-row :gutter="10">

    <el-col :span="6">
      <el-input v-model="query.RegistrationData.doctorName" placeholder="请输入医生姓名" style="width: 200px;" />
    </el-col>

<!--    <el-col :span="6">-->
<!--      <el-select v-model="query.RegistrationData.departmentId"-->
<!--                 :clearable="true"-->
<!--                 placeholder="请选择部门">-->
<!--        <el-option v-for="item in departments.data"-->
<!--                   :key="item.departmentId"-->
<!--                   :label="item.departmentName"-->
<!--                   :value="item.departmentId" />-->
<!--      </el-select>-->
<!--    </el-col>-->

    <el-col :span="6">
      <el-select v-model="query.RegistrationData.idDeal"
                 :clearable="true"
                 placeholder="是否被处理"
                 style="width:150px;">
        <el-option label="是" value="1" />
        <el-option label="否" value="0" />
      </el-select>
    </el-col>

    <el-col :span="6">
      <el-date-picker
        v-model="query.RegistrationData.useTime"
        type="date"
        placeholder="请选择日期"
        style="width:150px;"
        format="YYYY-MM-DD"
        value-format="YYYY-MM-DD"
      />
    </el-col>


    <el-col :span="6">
      <el-button type="primary" @click="getRegistrationDataData(query.RegistrationData)">搜索</el-button>
    </el-col>

  </el-row>
  <el-table :data="tableData.data" style="width: 100%;margin-top: 20px">

    <el-table-column label="序号" type="index" width="80" align="center">
    </el-table-column>

    <el-table-column label="患者姓名" prop="patientName" width="100" align="center">
    </el-table-column>

    <el-table-column label="科室" prop="departmentName" width="100" align="center">
    </el-table-column>

    <el-table-column label="就诊医生" prop="doctorName" width="100" align="center">
    </el-table-column>

    <el-table-column label="患者身份证" prop="identity" width="200" align="center">
    </el-table-column>

    <el-table-column label="时间" prop="time" width="100" align="center">
    </el-table-column>


    <el-table-column label="性别" prop="gender" width="80" align="center">
    </el-table-column>

    <el-table-column label="被处理" prop="isDeal" width="80" align="center">
    </el-table-column>


    <el-table-column label="使用日期" width="130px" align="center">
      <template #default="scope">
        <div style="display: flex; align-items: center">
          <el-icon>
            <timer />
          </el-icon>
          <span style="margin-left: 10px">{{ scope.row.useTime}}</span>
        </div>
      </template>
    </el-table-column>

    <el-table-column label="操作" width="200px" align="center">
      <template #default="scope">
<!--        <el-button
          style="width: 60px;"
          size="small"
          @click="handleEdit(scope.row)"
        >修改
        </el-button>-->
        <el-button
          style="width: 60px;"
          size="small"
          type="danger"
          v-model:current-page="query.RegistrationData.pages"
          v-model:age-sizes="query.RegistrationData.size"
          @click="handleDelete(scope.row)"
        >删除
        </el-button
        >
      </template>
    </el-table-column>
  </el-table>
  <!--分页组件-->
  <div>
    <el-pagination
      small
      layout="total, prev, pager, next, jumper"
      :total="tableData.total"
      class="pagiantion "
      @current-change="pageChange"
      v-model:current-page="query.RegistrationData.pages"
      v-model:page-size="query.RegistrationData.size"
    />
  </div>
</template>

<script lang="js" setup>
import { Timer } from "@element-plus/icons-vue";
import { onMounted, reactive } from "vue";
import { deleteRegistration, getRegistration } from "@/utils/RegistrationRequest";
import { ElMessage, ElMessageBox } from "element-plus";
import { useRouter } from "vue-router";

const router = useRouter();
//展示数据
const tableData = reactive({
  data: [],
  total: 0,
  current: 1, //当前页数
  size: 2  //每页显示几条数据
});
const departments = reactive({
  data: []
});
//请求参数
const query = reactive({
  RegistrationData: {
    "useTime":"",
    "idDeal":"",
    "patientName":"",
    "doctorName":"",
    "pages": tableData.current,
    "size": tableData.size,
  }
});


//组件加载时触发
onMounted(() => {
  getRegistrationDataData(query.RegistrationData);
});

//获取数据
const getRegistrationDataData = async (requestData) => {
  let res = await getRegistration(requestData);
  tableData.data = res.data;
  tableData.total = res.total;
  tableData.current = res.current;
};

//分页的页码变化时触发
const pageChange = () => {
  // console.log(query.employeeData.pages);
  getRegistrationDataData(query.RegistrationData);
};

//修改回调
const handleEdit = (row) => {
  router.push({
    path:'/home/updatemps',
    query:{id:row.registrationId}
  })
};

//删除
const handleDelete = (row) => {
  ElMessageBox.confirm(
    "确定要删除吗?",
    "警告",
    {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning"
    }
  )
    .then(async () => {
      let res = await deleteRegistration(row.registrationId);
      if (res.data) {
        ElMessage({
          type: "success",
          message: "删除成功"
        });
      } else {
        ElMessage({
          type: "error",
          message: "删除成功"
        });
      }
      getRegistrationDataData(query.RegistrationData);

    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "取消删除"
      });
    });
};

</script>

<style scoped>
</style>